import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileOperations {
	public static int CompleteWrite = 0;
	public static int TotalRead = 0;
	public static int TotalWrite = 0;

	public static boolean fileExists(String file) {
		File f = new File(file);
		if (f.exists()) {
			return true;
		} else {
			return false;
		}
	}

	public static final byte[] readFile(String name) {
		try {
			File file = new File(name);
			int i = (int) file.length();
			byte abyte0[] = new byte[i];
			DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(
			new FileInputStream(name)));
			datainputstream.readFully(abyte0, 0, i);
			datainputstream.close();
			FileOperations.TotalRead++;
			return abyte0;
		} catch (Exception exception) {
		}
		return null;
	}

	public static final void writeFile(String name, byte data[]) {
		try {
			(new File((new File(name)).getParent())).mkdirs();
			FileOutputStream fileoutputstream = new FileOutputStream(name);
			fileoutputstream.write(data, 0, data.length);
			fileoutputstream.close();
			FileOperations.TotalWrite++;
			FileOperations.CompleteWrite++;
		} catch (Throwable throwable) {
			System.out.println((new StringBuilder()).append("Write Error: ").append(name)
			.toString());
		}
	}
}